require 'watir'
include Watir
require 'test/unit'
require '../watir.config.rb'
require '../resources/functions.rb'
require 'win32ole'
require 'win32/process'

class TC_GroupMedia_test < Test::Unit::TestCase
   
    def startup
      $GroupCategoryName= 'GroupCategory1'
      $GroupCategoryDescription = 'This is the first group category'
      $HubName = 'Group1'
      $AppKey = 'GroupAppKey1'
      $HubDescription = 'This is the first group'
      $Description = 'This is to test forum options for groups'
      $Subject = 'MediaGroup1'
      $MediaGalleryPostName1 = 'Media Post1'
      $MediaGalleryPostNameEdit1 = $MediaGalleryPostName1+'_Edit'
      $MediaGalleryDescription1 ='This is to test first media post  in groups'
      $MediaGalleryDescriptionEdit1 = $MediaGalleryDescription1 +'_Edit'
      $AllTags1= 'first,media,post,automated'
      $AllTagsEdit1 =$AllTags1+','+'TagEdit'
      $Url1 ='http://www.freefoto.com/images/15/10/15_10_25---Sunset--Hastings_web.jpg?&k=Sunset%2C+Hastings'
      $MediaGalleryPostName2='Media Post2'
      $MediaGalleryDescription2 ='This is to test second media posts in groups'
      $AllTags2= 'second'
      $Url2 ='http://www.freefoto.com/images/15/20/15_20_2---Waterfall--Lake-Vyrnwy--Wales_web.jpg?&k=Waterfall%2C+Lake+Vyrnwy%2C+Wales'
      $MediaGalleryPostName3= 'Media Post3'
      $MediaGalleryDescription3= 'This is to test third media posts in groups'
      $AllTags3= 'third'
      $Url3 ='http://www.freefoto.com/images/1341/07/1341_07_55---The-Blue-Lagoon--Iceland-_web.jpg?&k=The+Blue+Lagoon%2C+Iceland.'
      $MediaGalleryPostName4='Media Post4'
      $MediaGalleryDescription4='This is to test fourth media posts in groups'
      $AllTags4= 'fourth'
      $Url4 ='http://www.freefoto.com/images/45/11/45_11_9---Sunrise_web.jpg?&k=Sunrise'
      $UserName = 'User1'
      $UserPassword = 'pass123'
      $UserEmail = 'user@user.com'
      $Member = 'User1'
      $Comments = 'Testing Comments'
      $EditNotes = 'Testing Edits'
      @@ie = Watir::IE.start($SITE_URL)
    end
    
    def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
    end
    
     def test_0000
        require 'win32/process'
        $pid = Process.create(
        :app_name      => 'ruby ../resources/clickers.rb',
        :creation_flags  => Process::DETACHED_PROCESS
        ).process_id
    end  
    
   
    def test_01_verifyHomeText
        assert(ie.contains_text(/Community Server/))		
    end
      
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
        ie.link(:text, 'Sign in').click
        assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
        ie.text_field(:id, /username$/).value = $ADMIN_USER
        assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
        ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
        assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
	  end
	  
    def test_05_submitLoginForm
        if(ie.button(:id, /loginButton$/).exists?)
          ie.button(:id, /loginButton$/).click
        else
        ie.link(:id, /loginButton$/).click
        end
        test_01_verifyHomeText
    end
    
    def test_06_verifyControlPanel
        assert(ie.link(:text, /Control Panel/).exists?)
        ie.link(:text, /Control Panel/).click
        assert(ie.contains_text(/Announcements/))
        assert(ie.link(:text, /System Administration/).exists?)
        ie.link(:text, /System Administration/).click
        assert(ie.contains_text(/Announcements/))
    end
    
    def test_07_verifyControlPanelLinks
        assert_equal $SITE_URL + 'controlpanel/', ie.link(:text, 'Dashboard').href
        assert_equal $SITE_URL + 'controlpanel/setup.aspx', ie.link(:text, 'Administration').href
        assert_equal $SITE_URL + 'controlpanel/BlogAdmin/', ie.link(:text, 'Blog Administration').href
        assert_equal $SITE_URL + 'controlpanel/MediaGalleryAdmin/', ie.link(:text, 'Media Galleries Administration').href
        assert_equal $SITE_URL + 'controlpanel/Forums/', ie.link(:text, 'Forum Administration').href
        assert_equal $SITE_URL + 'controlpanel/HubAdmin/', ie.link(:text, 'Group Administration').href
        assert_equal $SITE_URL + 'controlpanel/Membership/membersearch.aspx?SelectedNavItem=BrowseMembers', ie.link(:text, 'Membership Administration').href
        assert_equal $SITE_URL + 'controlpanel/Settings/default.aspx', ie.link(:text, 'Site Administration').href
    end
    
    def test_08_navigateToGroupAdministration
        ie.goto($SITE_URL + 'controlpanel/HubAdmin/')
        assert(ie.contains_text(' Group Administration '))      
    end  
    def test_09_verifyLinksExist
      # Make sure that all of the links exist
        assert(ie.link(:text, 'Log Out').exists?)
        assert(ie.link(:text, 'Help').exists?)
        assert(ie.link(:text, 'Go to Site').exists?)
        assert(ie.link(:text, 'Dashboard').exists?)
        assert(ie.link(:text, 'Administration').exists?)
        assert(ie.link(:text, 'Group Administration').exists?)
        assert(ie.link(:text, 'Telligent').exists?)
    end
      
    def test_10_navigateToAddCategory
        ie.goto($SITE_URL +'controlpanel/HubAdmin/groups.aspx')
        assert(ie.button(:id,/NewGroup$/).exists?)
        ie.button(:id,/NewGroup$/).click
        sleep 5
        assert(ie.frame(:index,1).text_field(:id,/GroupName$/).exists?)
        ie.frame(:index,1).text_field(:id,/GroupName$/).value =$GroupCategoryName
        assert(ie.frame(:index,1).text_field(:id,/GroupDesc$/).exists?)
        ie.frame(:index,1).text_field(:id,/GroupDesc$/).value =$GroupCategoryDescription
        assert(ie.frame(:index,1).link(:id,/SaveButton$/).exists?)
        ie.frame(:index,1).link(:id,/SaveButton$/).click
        sleep 3
      end
    def test_11_createUser 
        ie.goto($SITE_URL +'controlpanel/membership/UserAdd.aspx')
        assert(ie.text_field(:id,/username$/).exists?)
        ie.text_field(:id,/username$/).value = $UserName
        assert(ie.text_field(:id,/password$/).exists?)
        ie.text_field(:id,/password$/).value = $UserPassword
        password=ie.text_field(:id,/password$/).value
        assert(ie.text_field(:id,/password2$/).exists?)
        ie.text_field(:id,/password2$/).value =password
        assert(ie.text_field(:id,/email$/).exists?)
        ie.text_field(:id,/email$/).value = $UserEmail
        assert(ie.select_list(:id,/timezone$/).exists?)
        ie.select_list(:id,/timezone$/).select('(GMT +05:00) Islamabad, Karachi, Tashkent')
        assert(ie.button(:name,/createButton$/).exists?)
        ie.button(:name,/createButton$/).click
    end
   
    def test_12_navigateToCreateGroup
        ie.goto($SITE_URL+'groups/')
        sleep 3
        assert(ie.link(:text,'Create a new group').exists?)
        ie.link(:text,'Create a new group').click
        sleep 3
        assert(ie.text_field(:id,/HubName$/).exists?)
        ie.text_field(:id,/HubName$/).value =$HubName
        $HubName1 =  $HubName.downcase
        sleep 3
        ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_bcr_bcr_ctl00_ctl02_HubDescription_ctl00_Editor').execCommand('mceSetContent', false,'"+$HubDescription+"')")
        sleep 3
        assert(ie.radio(:id,/HubType_0$/).exists?)
        assert(ie.radio(:id,/HubType_1$/).exists?)
        assert(ie.radio(:id,/HubType_2$/).exists?)
        ie.radio(:id,/HubType_0$/).set
        assert(ie.select_list(:id,/HubGroup$/).exists?)
        sleep 2
        ie.select_list(:id,/HubGroup$/).select($GroupCategoryName)
        assert(ie.button(:id,/Create$/).exists?)
        ie.button(:id,/Create$/).click
      end
      
      def test_13_EditGroup
        sleep 5
        ie.goto($SITE_URL+'/groups/'+$HubName1+'/edit.aspx')
        # Media Options
        assert(ie.checkbox(:id,/EnableModeration$/).exists?)
        ie.checkbox(:id,/EnableModeration$/).set
        # Save 
        assert(ie.button(:id,/Save$/).exists?)
        ie.button(:id,/Save$/).click     
    end
      
    def test_14_navigateToaddMember
      sleep 2
      ie.goto($SITE_URL+'groups/')
      sleep 2
      ie.goto($SITE_URL+'groups/'+$HubName1+'/members.aspx')
      sleep 2
      assert(ie.text_field(:id,/UserName/).exists?)
      sleep 2
      ie.text_field(:id,/UserName/).value = $Member
      assert(ie.select_list(:id,/MembershipType$/).exists?)
      sleep 2
      ie.select_list(:id,/MembershipType$/).select('Manager')
      sleep 2
      assert(ie.button(:value,'Add Member').exists?)
      ie.button(:value,'Add Member').click
      sleep 5
    end

  
  def test_15_uploadFile
      test_02_verifyLoginLinksExist
      test_03_navigateToLogin
      ie.text_field(:id, /username$/).value = $UserName
      ie.text_field(:id, /password$/).value = $UserPassword
      if(ie.button(:id, /loginButton$/).exists?)
          ie.button(:id, /loginButton$/).click
        else
        ie.link(:id, /loginButton$/).click
        end
      sleep 2
      ie.goto($SITE_URL+'groups/')
      sleep 2
      if(ie.link(:text, $GroupCategoryName).exists?)
      sleep 2
      ie.link(:text, $GroupCategoryName).click
      sleep 5
      end
      assert(ie.link(:text, $HubName).exists?)
      sleep 5
      ie.link(:text, $HubName).click
      sleep 5
      ie.link(:href,$SITE_URL+'groups/'+$HubName1 +'/media/default.aspx').click
      sleep 5
      ie.link(:href,$SITE_URL+'groups/'+$HubName1 +'/media/default.aspx').click
      sleep 5
      assert(ie.link(:text,'Upload').exists?)
      sleep 5
      ie.link(:text,'Upload').click
      # File 1
      sleep 5
      assert(ie.button(:value,'Specify File/URL').exists?)
      sleep 5
      ie.button(:value,'Specify File/URL').click
      sleep 5
      assert(ie.frame(:index,2).radio(:id,/LinkToUrl$/).exists?)
      ie.frame(:index,2).radio(:id,/LinkToUrl$/).set
      assert(ie.frame(:index,2).text_field(:id,/Url$/).exists?)
      ie.frame(:index,2).text_field(:id,/Url$/).value = $Url1
      assert(ie.frame(:index,2).button(:id,/Save$/).exists?)
      ie.frame(:index,2).button(:id,/Save$/).click
      assert(ie.text_field(:id,/MediaGalleryPostName$/).exists?)
      ie.text_field(:id,/MediaGalleryPostName$/).value = $MediaGalleryPostName1
      sleep 2
      ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_ctl00_bcr_bcr_bcr_MediaGalleryPostForm_ctl05_MediaGalleryPostDescription_ctl00_Editor').execCommand('mceSetContent', false,'"+$MediaGalleryDescription1+"')")
      sleep 2
      assert(ie.text_field(:id,/Tags$/).exists?)
      ie.text_field(:id,/Tags$/).value = $AllTags1
      assert(ie.button(:id,/MediaGalleryPostSave$/).exists?)
      ie.button(:id,/MediaGalleryPostSave$/).click
      # File 2
      sleep 2
      assert(ie.link(:text,'Upload New File').exists?)
      sleep 2
      ie.link(:text,'Upload New File').click
      sleep 2
      assert(ie.button(:value,'Specify File/URL').exists?)
      ie.button(:value,'Specify File/URL').click
      sleep 5
      assert(ie.frame(:index,2).radio(:id,/LinkToUrl$/).exists?)
      ie.frame(:index,2).radio(:id,/LinkToUrl$/).set
      assert(ie.frame(:index,2).text_field(:id,/Url$/).exists?)
      ie.frame(:index,2).text_field(:id,/Url$/).value = $Url2
      assert(ie.frame(:index,2).button(:id,/Save$/).exists?)
      ie.frame(:index,2).button(:id,/Save$/).click
      assert(ie.text_field(:id,/MediaGalleryPostName$/).exists?)
      ie.text_field(:id,/MediaGalleryPostName$/).value = $MediaGalleryPostName2
      sleep 2
      ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_ctl00_bcr_bcr_bcr_MediaGalleryPostForm_ctl05_MediaGalleryPostDescription_ctl00_Editor').execCommand('mceSetContent', false,'"+$MediaGalleryDescription2+"')")
      assert(ie.text_field(:id,/Tags$/).exists?)
      ie.text_field(:id,/Tags$/).value = $AllTags2
      assert(ie.button(:id,/MediaGalleryPostSave$/).exists?)
      ie.button(:id,/MediaGalleryPostSave$/).click
      assert(ie.link(:text,'Upload New File').exists?)
      sleep 2
      ie.link(:text,'Upload New File').click
      sleep 2
      assert(ie.button(:value,'Specify File/URL').exists?)
      ie.button(:value,'Specify File/URL').click
      sleep 5
      assert(ie.frame(:index,2).radio(:id,/LinkToUrl$/).exists?)
      ie.frame(:index,2).radio(:id,/LinkToUrl$/).set
      assert(ie.frame(:index,2).text_field(:id,/Url$/).exists?)
      ie.frame(:index,2).text_field(:id,/Url$/).value = $Url3
      assert(ie.frame(:index,2).button(:id,/Save$/).exists?)
      ie.frame(:index,2).button(:id,/Save$/).click
      assert(ie.text_field(:id,/MediaGalleryPostName$/).exists?)
      ie.text_field(:id,/MediaGalleryPostName$/).value = $MediaGalleryPostName3
      sleep 2
      ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_ctl00_bcr_bcr_bcr_MediaGalleryPostForm_ctl05_MediaGalleryPostDescription_ctl00_Editor').execCommand('mceSetContent', false,'"+$MediaGalleryDescription3+"')")
      sleep 2
      assert(ie.text_field(:id,/Tags$/).exists?)
      ie.text_field(:id,/Tags$/).value = $AllTags3
      assert(ie.button(:id,/MediaGalleryPostSave$/).exists?)
      ie.button(:id,/MediaGalleryPostSave$/).click
      assert(ie.link(:text,'Upload New File').exists?)
      sleep 2
      ie.link(:text,'Upload New File').click
      sleep 2
      assert(ie.button(:value,'Specify File/URL').exists?)
      ie.button(:value,'Specify File/URL').click
      sleep 5
      assert(ie.frame(:index,2).radio(:id,/LinkToUrl$/).exists?)
      ie.frame(:index,2).radio(:id,/LinkToUrl$/).set
      assert(ie.frame(:index,2).text_field(:id,/Url$/).exists?)
      ie.frame(:index,2).text_field(:id,/Url$/).value = $Url4
      assert(ie.frame(:index,2).button(:id,/Save$/).exists?)
      ie.frame(:index,2).button(:id,/Save$/).click
      assert(ie.text_field(:id,/MediaGalleryPostName$/).exists?)
      ie.text_field(:id,/MediaGalleryPostName$/).value = $MediaGalleryPostName4
      sleep 2
      ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_ctl00_bcr_bcr_bcr_MediaGalleryPostForm_ctl05_MediaGalleryPostDescription_ctl00_Editor').execCommand('mceSetContent', false,'"+$MediaGalleryDescription4+"')")
      sleep 2
      assert(ie.text_field(:id,/Tags$/).exists?)
      ie.text_field(:id,/Tags$/).value = $AllTags4
      assert(ie.button(:id,/MediaGalleryPostSave$/).exists?)
      ie.button(:id,/MediaGalleryPostSave$/).click
      sleep 3
    end
    
    def test_16_commentMediaFile
      test_02_verifyLoginLinksExist
      test_03_navigateToLogin
      test_04_populateLoginForm
      test_05_submitLoginForm
      ie.goto($SITE_URL+'groups/')
      sleep 2
      assert(ie.link(:text, $HubName).exists?)
      sleep 5
      ie.link(:text, $HubName).click
      sleep 2
      ie.goto($SITE_URL+'groups/'+$HubName1 +'/media/default.aspx')
      sleep 5
      assert(ie.link(:text,$MediaGalleryPostName2).exists?)
      sleep 5
      ie.link(:text,$MediaGalleryPostName2).click
      sleep 5
      assert(ie.link(:text,'Add file to favorites').exists?)
      sleep 5
      ie.link(:text,'Add file to favorites').click
      sleep 5
      assert(ie.link(:text,'Add gallery to favs').exists?)
      sleep 5
      ie.link(:text,'Add gallery to favs').click
      sleep 5
      assert(ie.text_field(:id,/CommentBody$/).exists?)
      sleep 5
      ie.text_field(:id,/CommentBody$/).set($Comments)
      sleep 5
      assert(ie.button(:id,/CommentSubmit$/).exists?)
      sleep 5
      ie.button(:id,/CommentSubmit$/).click
      sleep 5
    end
    
    def test_17_viewFiles
        assert(ie.link(:text,'Previous').exists?)
        ie.link(:text,'Previous').click
        sleep 1
        assert(ie.link(:text,'Previous').exists?)
        ie.link(:text,'Previous').click
        sleep 1
        assert(ie.link(:text,'Previous').exists?)
        ie.link(:text,'Previous').click
        sleep 1
        assert(ie.link(:text,'Previous').exists?)
        ie.link(:text,'Previous').click
        sleep 1
        assert(ie.link(:text,'Next').exists?)
        ie.link(:text,'Next').click
        sleep 1
        assert(ie.link(:text,'Next').exists?)
        ie.link(:text,'Next').click
        sleep 1
        assert(ie.link(:text,'Next').exists?)
        ie.link(:text,'Next').click
        sleep 1
        assert(ie.link(:text,'View slideshow').exists?)
        sleep 2
        ie.link(:text,'View slideshow').click
        sleep 30
      end
      
    def test_18_editFile
        test_02_verifyLoginLinksExist
        test_03_navigateToLogin
        ie.text_field(:id, /username$/).value = $UserName
        ie.text_field(:id, /password$/).value = $UserPassword
         if(ie.button(:id, /loginButton$/).exists?)
          ie.button(:id, /loginButton$/).click
        else
        ie.link(:id, /loginButton$/).click
        end
        sleep 2
        ie.goto($SITE_URL +'groups/')
        sleep 4
        ie.goto($SITE_URL+'groups/'+$HubName1 +'/media/default.aspx')
        sleep 3
        assert(ie.link(:text,$MediaGalleryPostName1).exists?)
        sleep 2
        ie.link(:text,$MediaGalleryPostName1).click
        sleep 2
        assert(ie.link(:text,'Edit this File').exists?)
        ie.link(:text,'Edit this File').click
        assert(ie.text_field(:id,/MediaGalleryPostName$/).exists?)
        ie.text_field(:id,/MediaGalleryPostName$/).value = $MediaGalleryPostNameEdit1
        sleep 2
        ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_ctl00_bcr_bcr_bcr_MediaGalleryPostForm_ctl05_MediaGalleryPostDescription_ctl00_Editor').execCommand('mceSetContent', false,'"+$MediaGalleryDescriptionEdit1+"')")
        sleep 2
        assert(ie.text_field(:id,/Tags$/).exists?)
        ie.text_field(:id,/Tags$/).value = $AllTagsEdit1
        assert(ie.button(:id,/MediaGalleryPostSave$/).exists?)
        ie.button(:id,/MediaGalleryPostSave$/).click
      end
      
      def test_19_deleteFile
      ie.goto($SITE_URL+'groups/'+$HubName1 +'/media/default.aspx')
      sleep 3
      assert(ie.link(:text,$MediaGalleryPostNameEdit1).exists?)
      sleep 2
      ie.link(:text,$MediaGalleryPostNameEdit1).click
      sleep 2
      assert(ie.link(:text,'Delete this File').exists?)
      sleep 2
      ie.link(:text,'Delete this File').click
      sleep 5 
      assert(ie.link(:text,$MediaGalleryPostName3).exists?)
      sleep 3
      ie.link(:text,$MediaGalleryPostName3).click
      sleep 2
      assert(ie.link(:text,'Delete this File').exists?)
      sleep 2
      ie.link(:text,'Delete this File').click
      sleep 5
      assert(ie.link(:text,$MediaGalleryPostName4).exists?)
      sleep 3
      ie.link(:text,$MediaGalleryPostName4).click
      sleep 2
      assert(ie.link(:text,'Delete this File').exists?)
      sleep 2
      ie.link(:text,'Delete this File').click
    end
    def test_20_DeleteCommentedFile
      test_02_verifyLoginLinksExist
      test_03_navigateToLogin
      test_04_populateLoginForm
      test_05_submitLoginForm
      sleep 5
       ie.goto($SITE_URL +'groups/')
       sleep 3
       ie.goto($SITE_URL+'groups/'+$HubName1 +'/media/default.aspx')
      sleep 5
      assert(ie.link(:text,$MediaGalleryPostName2).exists?)
      sleep 3
      ie.link(:text,$MediaGalleryPostName2).click
      sleep 2
      assert(ie.link(:text,'Delete this File').exists?)
      sleep 2
      ie.link(:text,'Delete this File').click
      sleep 5
    end
    
    def test_21_DeleteGroup
         ie.goto($SITE_URL+'controlpanel/HubAdmin/hubs.aspx')
        assert(ie.link(:text,'All').exists?)
        ie.link(:text,'All').click
        assert(ie.table(:id,'BlogLists').exists?)
        table1 = ie.table(:id, 'BlogLists')
        rowcount = table1.row_count
        rowcount1 =1
        while rowcount1<=rowcount
            if (table1[rowcount1][1].link(:text,$HubName1).exists?)
              ok =1
               sleep 5
               table1[rowcount1][6].link(:text, 'Delete').click
               break
             end   
            rowcount1=rowcount1+1
        end
      end
      
       def test_22_navigateToDeleteCategory
        ie.goto($SITE_URL+'controlpanel/HubAdmin/groups.aspx')
        sleep 5
        assert(ie.hidden(:id,'ctl00_ctl00_ctl00_OuterTaskRegion_TaskRegion_TaskRegion_TaskRegion_CategoriesTree').exists?)
        hiddenvalue=ie.hidden(:id,'ctl00_ctl00_ctl00_OuterTaskRegion_TaskRegion_TaskRegion_TaskRegion_CategoriesTree').value
        hiddenvaluearr=hiddenvalue.split('&')
        groupid=hiddenvaluearr[hiddenvaluearr.length-1].split('=')
        ie.ie.Document.parentWindow.execScript("ctl00_ctl00_ctl00_OuterTaskRegion_TaskRegion_TaskRegion_TaskRegion_CategoriesTree.SelectNode(ctl00_ctl00_ctl00_OuterTaskRegion_TaskRegion_TaskRegion_TaskRegion_CategoriesTree.GetNodeByValue("+groupid[1]+"))")
        sleep 5
        assert(ie.button(:value ,'Delete').exists?)
        ie.button(:value ,'Delete').click
      end
      
      def test_23_searchUser
        ie.goto($SITE_URL +'controlpanel/membership/membersearch.aspx?SelectedNavItem=BrowseMembers')
        assert(ie.text_field(:id,/searchText$/).exists?)
        ie.text_field(:id,/searchText$/).value ="*"
        assert(ie.select_list(:name,/PageList$/).exists?)
        ie.select_list(:name,/PageList$/).select('10')
        sleep 3
        assert(ie.button(:id,/searchButton$/).exists?)
        sleep 2
        ie.button(:id,/searchButton$/).click
      end
      
      def test_24_navigateToDeleteUser
        sleep 5
        table1 = ie.table(:index, 6)
        rowcount = table1.row_count
        rowcount1 =1
        ok =0
        while rowcount1<=rowcount
            if (table1[rowcount1][1].link(:text,$UserName).exists?)
              ok =1
               sleep 5
               table1[rowcount1][5].button(:value, 'Delete').click
               sleep 3
               break
             end   
         rowcount1=rowcount1+1
        end
       if(ok ==0)
         sleep 5
         ie.link(:text,'Next >').click
         sleep 5
         test_24_navigateToDeleteUser
       end
       sleep 5
       assert(ie.frame(:index,1).radio(:id,/AssignToAnonymous$/).exists?)
       ie.frame(:index,1).radio(:id,/AssignToAnonymous$/).set
       sleep 3
       assert(ie.frame(:index,1).button(:id,/DeleteUserButton$/).exists?)
       sleep 3
       ie.frame(:index,1).button(:id,/DeleteUserButton$/).click
       sleep 5
       ie.goto($SITE_URL +'controlpanel/membership/membersearch.aspx?SelectedNavItem=BrowseMembers')
       assert(ie.text_field(:id,/searchText$/).exists?)
       ie.text_field(:id,/searchText$/).value ="*"
       sleep 3
       assert(ie.button(:id,/searchButton$/).exists?)
       sleep 2
       ie.button(:id,/searchButton$/).click  
       if(ie.link(:text,$UserName).exists?)
       puts 'User Not Deleted'
       end   
    end
   
     def test_99_Exit
         ie.close
       end
 
end
      